package com.kylin.upms.biz.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.kylin.upms.biz.dto.RoleDao;
import com.kylin.upms.biz.dto.UserDto;
import com.kylin.upms.biz.entity.Role;
import com.kylin.upms.biz.entity.User;
import com.kylin.upms.biz.service.IRoleService;
import com.kylin.upms.biz.vo.ResEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2019-09-15
 */
@RestController
@RequestMapping("/role")
public class RoleController {

   @Autowired
    IRoleService iRoleService;

    @ApiOperation("根据查询条件分页查询用户列表")
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public ResEntity get(RoleDao roleDao){
        System.out.println("我已经进来了"+roleDao.getPageSize());
        int pages = roleDao.getPageNum();
        Page<Role> page = new Page<Role>(roleDao.getPageNum(),roleDao.getPageSize());
        Role role = new Role();
        BeanUtils.copyProperties(roleDao,role);
        EntityWrapper entityWrapper = new EntityWrapper(role);
        entityWrapper.like("name",role.getName());
        Page page1 = iRoleService.selectPage(page, entityWrapper);
        return ResEntity.ok(page1);
    }
    @RequestMapping(value = "/roleadd",method = RequestMethod.GET)
    public ResEntity adda(Role u){
        System.out.println("****************************************************"+u);
        boolean insert = iRoleService.insert(u);
        if (insert){
            return  ResEntity.ok("新增成功");
        }
        return   ResEntity.error("新增失败");

    }

}
